﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EuroManager.Domain.Simulator.Engine;
using EuroManager.Domain.Simulator.Engine.Movements;
using NUnit.Framework;

namespace EuroManager.Domain.Simulator.Tests.Engine.Movements
{
    [TestFixture]
    public class StillMovementTests
    {
        [Test]
        public void ShouldNotMoveWhenVelocityIsZero()
        {
            Vector2D location = new Vector2D(1, 3);

            StillMovement movement = new StillMovement(location, Vector2D.Zero, 1);
            movement.Update(0.1f);

            Assert.AreEqual(location, movement.Location);
        }

        [Test]
        public void ShouldAdvanceLocation()
        {
            Vector2D location = new Vector2D(1, 3);

            StillMovement movement = new StillMovement(location, new Vector2D(-2, -2), 1);
            movement.Update(0.1f);

            Assert.AreNotEqual(location, movement.Location);
        }

        [Test]
        public void ShouldStopEventually()
        {
            StillMovement movement = new StillMovement(new Vector2D(-3, 2), new Vector2D(5, 4), 1);
            TestHelper.Advance(100, movement);

            Assert.IsTrue(movement.Velocity.IsZero);
        }

        [Test]
        public void ShouldNeverFinish()
        {
            StillMovement movement = new StillMovement(new Vector2D(30, 20), new Vector2D(5, 4), 1);
            TestHelper.Advance(100, movement);

            Assert.IsFalse(movement.IsFinished);
        }

        [Test]
        public void ShouldStopOnPathIndicatedByVelocity()
        {
            Vector2D velocity = new Vector2D(5, 4);
            Vector2D startLocation = new Vector2D(30, 20);
            StillMovement movement = new StillMovement(startLocation, velocity, 1);

            TestHelper.Advance(100, movement);
            Vector2D path = movement.Location - startLocation;

            Assert.IsTrue(path.IsParallelWithSense(velocity));
        }

        [Test]
        public void ShouldNeverReverseVelocity()
        {
            bool reversed = false;
            StillMovement movement = new StillMovement(new Vector2D(-3, 2), new Vector2D(5, 4), 1);

            Action reversedCheckAction = () => reversed |= movement.Velocity.X < 0 || movement.Velocity.Y < 0;
            TestHelper.Advance(100, reversedCheckAction, movement);

            Assert.IsFalse(reversed);
        }
    }
}
